<template>
    <keep-alive>
        <component :is="AsyncComponent" v-bind="$attrs" v-on="$listeners" />
    </keep-alive>
</template>

<script>
// 获取 bizConf 对象
import bizJSConf from '@/bizConf.json'
import factory from '@/common/utils/factory.js'

/**
 * 动态文件加载器
 */
export default {
    inheritAttrs: false,
    // 外部传入属性
    props: {
    // 是否保持缓存
        keepAlive: {
            type: Boolean,
            required: false,
            default: true
        },
        // 延迟加载时间
        delay: {
            type: Number,
            default: 20
        },
        // 超时警告时间
        timeout: {
            type: Number,
            default: 2000
        }
    },
    data() {
        return {
            path: '',
            // 构建异步组件 - 懒加载实现
            AsyncComponent: factory(this.path, this.delay, this.timeout)
        }
    },
    created() {
        const id = this.$route.params.id
        this.path = bizJSConf[id].path
        this.load()
    },
    methods: {
        load() {
            this.AsyncComponent = factory(this.path, this.delay, this.timeout)
        }
    }
}
</script>
